﻿using SIMS.SqlSugarWebApi.Models;
using SIMS.SqlSugarWebApi.ServiceInterface;

namespace SIMS.SqlSugarWebApi.Services
{
    public class LoginService : ILoginService
    {
        private DataContext _context;

        public LoginService(DataContext context)
        {
            _context = context;
        }

        public async Task<int> Login(string username, string password)
        {
            var item = await _context.db.Queryable<User>().SingleAsync(i => i.UserName == username && i.Password == password);
            return item?.Id ?? 0;
        }
    }
}
